#ifndef CENGINE_H
#define CENGINE_H

#include "params.h"
#include "CBoard.h"

class CEngine 
{	
	
	CBoard * board;

	public:
		
	int engine_case;
		
	CEngine() { engine_case = 0; };
	~CEngine() {};
			
	int setup( CBoard * b );
			
   	/** Returns true if the thread was successfully started, false if there was an error starting the thread */
   	bool StartInternalThread()
   	{
   		engine_case = MSG_GO;
		return (pthread_create(&_thread, NULL, InternalThreadEntryFunc, this) == 0);
	}

	/** Will not return until the internal thread has exited. */
	void WaitForInternalThreadToExit()
	{	
		(void) pthread_join(_thread, NULL);
	}
		
	protected:
	/** Implement this method in your subclass with the code you want your thread to run. */
	void InternalThreadEntry();
   
	private:
	static void * InternalThreadEntryFunc(void * This) {((CEngine *)This)->InternalThreadEntry(); return NULL;}

   pthread_t _thread;
};

#endif
